// import path from "path";

const express = require("express");
const fs = require("fs");

const app = express();

app.use("/", express.static("base/dist"));
app.use("/base", express.static("base/dist"));
app.use("/common", express.static("common/dist"));
app.use("/fl", express.static("apps/fl/dist"));

app.use(function (req, res) {
  console.log("收到：#" + req.url + "#");
  if (["", "/", "/index.html"].includes(req.url)) {
    fs.readFile("./base/dist/index.html", function (err, fileData) {
      res.writeHead(200, { "Content-Type": "text/html;charset=utf-8" }); // 解决乱码问题
      res.end(fileData.toString());
    });
  } else {
    res.sendStatus(404);
  }
});

app.listen(1222, () => {
  console.log("你可以访问: http://localhost:1222 ");
});
